package com.wibo.account;

import java.util.ArrayList;

import com.wibo.common.UserItem;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class UserListItemAdapter extends BaseAdapter {
	
	private Context mContext;
	private ArrayList<UserItem> mItemData;

	public UserListItemAdapter(Context mContext, ArrayList<UserItem> mItemData) {
		super();
		this.mContext = mContext;
		this.mItemData = mItemData;
	}

	public UserListItemAdapter(Context mContext) {
		super();
		this.mContext = mContext;
	}

	/**
	 * @param mItemData the mItemData to set
	 */
	public void setmItemData(ArrayList<UserItem> mItemData) {
		this.mItemData = mItemData;
	}

	@Override
	public int getCount() {
		if( mItemData == null ){
			return 0;
		}
		return mItemData.size();
	}

	@Override
	public UserItem getItem(int position) {
		// TODO Auto-generated method stub
		return mItemData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(mItemData == null ){
            return null;		
    	}
        if(convertView == null){
        	UserListItemView itemView = null;

        	itemView = new UserListItemView(mContext);

            itemView.updateView(mItemData.get(position), String.valueOf(position));
            convertView = itemView;
        }
        else
        {
            ((UserListItemView) convertView).updateView(mItemData.get(position),String.valueOf(position));
        }
    	return convertView;
	}

}
